package cn.virens.web.components.websocket;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeInterceptor;

import cn.virens.web.components.beetl.format.ImageFormat;

public class WebSocketHandshakeInterceptor implements HandshakeInterceptor {
	protected final Logger logger = LoggerFactory.getLogger(WebSocketHandshakeInterceptor.class);

	@Override
	public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
		logger.debug("WebSocketHandshakeInterceptor.beforeHandshake");

		// 登录信息
		attributes.put("login-avatar", ImageFormat.DEF_AVATAR);
		attributes.put("login-account", "admin");
		attributes.put("login-group", "test");
		attributes.put("login-name", "测试");

		return true;
	}

	@Override
	public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {
		logger.debug("WebSocketHandshakeInterceptor.afterHandshake");
	}

}
